package com.wiscamp.ninechapters.tags.infrastructure.mappers;

import com.wiscamp.ninechapters.tags.infrastructure.po.CourseOutlineView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Collection;

public interface CourseOutlineViewMapper extends JpaRepository<CourseOutlineView, Long>, JpaSpecificationExecutor<CourseOutlineView> {

    @Query(value = "select e from CourseOutlineView e where e.courseId = :courseId order by e.outlineLevel asc, e.parentId asc, e.outlineIndex asc")
    Collection<CourseOutlineView> findListByCourse(long courseId);

    @Query(value = "select e from CourseOutlineView e where e.courseId in (:courseIds) order by e.outlineLevel asc, e.parentId asc, e.outlineIndex asc")
    Collection<CourseOutlineView> findListByCourseIds(Collection<Long> courseIds);

    @Query(value = "select e from CourseOutlineView e where e.courseId = :courseId  and e.parentId = :parentId order by e.outlineLevel asc, e.parentId asc, e.outlineIndex asc")
    Collection<CourseOutlineView> findListByParent(long courseId, long parentId);

}